home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8968 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  49 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: argc/argv & switches
  5. Date: Thu, 07 Mar 96 17:36:39 GMT
  6. Organization: none
  7. Message-ID: <826220199snz@genesis.demon.co.uk>
  8. References: <4h2j8j$9gn@milo.freenet.vancouver.bc.ca> <danpop.825593142@rscernix> <313E0094.167EB0E7@fore.com> <4hl52oINNa4l@anvil.ugrad.cs.ubc.ca>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4hl52oINNa4l@anvil.ugrad.cs.ubc.ca>
  15.            c2a192@ugrad.cs.ubc.ca "Kazimir Kylheku" writes:
  16.  
  17. >However, if it were the case that these pointers are not modifiable, would not
  18. >the declaration of main() be required to be written as:
  19. >
  20. >int main(int argc, char * const *argv)
  21. >
  22. >        or
  23. >
  24. >int main(int argc, char * const argv[])
  25. >
  26. >That is, ``argv is a pointer to a vector of constant pointers to modifiable
  27. >chars''.
  28.  
  29. This is not required any more than the type of a string literal is required
  30. to be const char [x]. You can refer to a const object through a non-const
  31. lvalue however if you try to modify the object you get undefined
  32. behaviour. The const was probably left out to maintain backwards compatibilty
  33. with existing code. Such code could easily contain lines such as:
  34.  
  35.    char **ptr = argv;
  36.  
  37. which would break with a const declaration of argv. Of course the standard
  38. declaration breaks if I try to use:
  39.  
  40.    char *const *ptr = argv;
  41.  
  42. which is a pity but not disasterous!
  43.  
  44. -- 
  45. -----------------------------------------
  46. Lawrence Kirby | fred@genesis.demon.co.uk
  47. Wilts, England | 70734.126@compuserve.com
  48. -----------------------------------------
  49.